<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Model\Admin\CategoriesModel;
use App\Model\Admin\NewsModel;
use App\Model\Admin\ProductModel;
use App\Model\BannerModel;
use App\Model\ConfigModel;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function index()
    {
        $data['banner'] = BannerModel::get();

        // 产品分类
        $data['categories'] = CategoriesModel::where('pid',1)->get();
        // 产品
        $product_list = ProductModel::where('is_show',1)->get();
        // 获取产品树
        $productsController = new ProductsController();
        $data['products'] = $productsController->getTree($data['categories'], $product_list);
        // 推荐产品
        $data['recommend_products'] = ProductModel::where('is_show',1)
            ->where('is_recommend',1)
            ->get(['product_img','product_name','url']);
        // 技术中心
        $data['tech_center'] = \DB::table('tech_center')
            ->select(['id','img','title'])
            ->get();

        // 新闻
        $data['news'] = NewsModel::where('is_show',1)
            ->where('recommend',1)
            ->select(['id','news_title','abstract','img','created_at'])
            ->orderBy('id','desc')
            ->take(3)
            ->get();
        // SEO
        $data['seo'] = ConfigModel::where('config_type','index')
            ->first();
        return view('front.index')->with('data',$data);
    }

    /**
     * 关于我们
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function about()
    {
        $data['seo'] = ConfigModel::where('config_type','about')
            ->first();
        $data['tech_center'] = \DB::table('tech_center')
            ->select(['id','img','title'])
            ->get();
        return view('front.about')->with('data',$data);
    }

    /**
     * 关于我们
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function contact()
    {
        $data['seo'] = ConfigModel::where('config_type','contact')
            ->first();
        return view('front.contact')->with('data',$data);
    }
}
